<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<jsp:include page="../../base/header.jsp"></jsp:include>
<link rel="stylesheet" href="static/assets/css/bootstrap-datetimepicker.min.css" />
<link rel="stylesheet" type="text/css" href="static/plugins/webuploader/css/webuploader.css" />
<link rel="stylesheet" type="text/css" href="static/plugins/webuploader/image-upload/style.css" />
<style>
.col-sm-10 {
    width: 83.3333% !important;
}
</style>
<body style="background-color:#FFF;">
	<div class="page-header">
		<h1>
			产品管理
			<small>
				<i class="icon-double-angle-right"></i>
				产品管理
			</small>
		</h1>
	</div>
	<div class="row" style="width: 100%;">
		<div class="col-xs-12">
			<div class="table-responsive">
				<table id="sample-table-1" class="table table-striped table-bordered table-hover">
					<thead>
						<tr>
							<th class="center">
								<label>
									<input type="checkbox" class="ace"/>
									<span class="lbl"></span>
								</label>
							</th>
							<th>产品标题</th>
							<th>产品分类</th>
							<th>发布人</th>
							<th>发布时间</th>
							<th>融资金融(万)</th>
							<th>审核次数</th>
							<th>产品状态</th>
							<th></th>
						</tr>
					</thead>
					<tbody>
						
					</tbody>
				</table>
			</div><!-- /.table-responsive -->
			<div class=" no-margin-top">
				<ul class="pagination pull-right no-margin">
				</ul>
			</div>
			<button class="btn btn-primary btn-xs">
				<i class="single-add icon-edit bigger-160 icon-only" href="#modal-table" data-toggle="modal"></i>
			</button>
			<button class="btn btn-danger btn-xs">
				<i class="batch-del icon-trash bigger-160 icon-only"></i>
			</button>
			<div id="modal-table" class="modal fade" tabindex="-1"  style="display:block">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header no-padding">
							<div class="table-header">
							</div>
						</div>
						<div class="modal-body no-padding">
							<form class="form-horizontal" role="form" style="margin-top:2rem;">
								<div id="modal-table-container"></div>
								<div class="space-4"></div>
								<div class="form-group">
									<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 栏目封面 </label>
									<div class="col-sm-9">
										<div id="wrapper" class="no-margin">
									        <div id="container" class="uploader-container col-xs-10 col-sm-10 no-padding" style="padding-bottom: 10px !important;">
									            <div id="uploader">
									            	<input type="hidden" for-format="empty-uploader" />
									            	<input type="hidden" for-format="reload-uploader"  url="product/detail" delUrl="product/del/pic" v="0"/>
									           		<div class="queueList">
									                    <div id="dndArea" class="placeholder">
									                        <div id="filePicker"></div>
									                    </div>
									                </div>
									                <div class="statusBar" style="display:none;">
									                    <div class="info"></div>
									                </div>
									            </div>
									        </div>
									    </div>
									</div>
								</div>
								<div id="modal-table-btn"></div>
							</form>
						</div>
						<div class="modal-footer no-margin-top"></div>
					</div>
				</div>
			</div>
		</div><!-- /span -->
	</div>
	<script src="static/assets/js/bootbox.min.js"></script>
	<script src="static/assets/js/date-time/bootstrap-datetimepicker.min.js"></script>
	<script src="static/assets/js/jquery.gritter.min.js"></script>
	<script src="static/plugins/system-plugins.js"></script>
	<script type="text/javascript" src="static/plugins/webuploader/dist/webuploader.js"></script>
	<script type="text/javascript" src="static/plugins/webuploader/upload.upload.js"></script>
	<script type="text/javascript">
	$(function(){
		setTimeout(function(){
			$("#modal-table").css("display","none");
		},100);
		var names = [
			{
				name:'id',
				type:'main',
				input:'产品'
			},
			{
				name:'title',
				input:'产品标题',
				type:"disabled",
				size:'M'
			},
			{
				name:'productType',
				input:'产品分类',
				type:"disabled"
			},
			{
				name:'publisher',
				input:'发布人',
				type:"disabled"
			},
			{
				name:'publishTime',
				type:"hidden"
			},
			{
				name:'money',
				input:'融资金额',
				type:"disabled"
			},
			{
				name:'size',
				input:function(value,isInit,isChar){
					if(isChar)return '公司规模';
					if(isInit)return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="size" placeholder="公司规模"></textarea></div></div>';
					return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="size" placeholder="公司规模" disabled>' + value.size + '</textarea></div></div>';
				},
				isTd:false
			},
			{
				name:'period',
				input:function(value,isInit,isChar){
					if(isChar)return '融资周期';
					if(isInit)return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="period" placeholder="融资周期"></textarea></div></div>';
					return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="period" placeholder="融资周期" disabled>' + value.period + '</textarea></div></div>';
				},
				isTd:false
			},
			{
				name:'intro',
				input:function(value,isInit,isChar){
					if(isChar)return '产品简介';
					if(isInit)return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="intro" placeholder="产品简介"></textarea></div></div>';
					return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="intro" placeholder="产品简介" disabled>' + value.intro + '</textarea></div></div>';
				},
				isTd:false
			},
			{
				name:'condition',
				input:function(value,isInit,isChar){
					if(isChar)return '产品条件';
					if(isInit)return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="condition" placeholder="产品条件"></textarea></div></div>';
					return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="condition" placeholder="产品条件" disabled>' + value.condition + '</textarea></div></div>';
				},
				isTd:false
			},
			{
				name:'procedure',
				input:function(value,isInit,isChar){
					if(isChar)return '产品流程';
					if(isInit)return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="procedure" placeholder="产品流程"></textarea></div></div>';
					return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="procedure" placeholder="产品流程" disabled>' + value.procedure + '</textarea></div></div>';
				},
				isTd:false
			},
			{
				name:'department',
				input:function(value,isInit,isChar){
					if(isChar)return '联系部门';
					if(isInit)return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="department" placeholder="联系部门"></textarea></div></div>';
					return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="department" placeholder="联系部门" disabled>' + value.department + '</textarea></div></div>';
				},
				isTd:false
			},
			{
				name:'number',
				input:function(value,isInit,isChar){
					if(isChar)return '联系电话';
					if(isInit)return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="number" placeholder="联系电话"></textarea></div></div>';
					return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="number" placeholder="联系电话" disabled>' + value.number + '</textarea></div></div>';
				},
				isTd:false
			},
			{
				name:'deadline',
				input:function(value,isInit,isChar){
					if(isChar)return '截止时间';
					if(isInit)return '<div class="col-sm-9"><input class="date-picker col-xs-10 col-sm-10" data-date-format="yyyy/mm/dd hh:ii:ss" type="text" value="" readonly/></div></div>';
					return '<div class="col-sm-9"><input class="form-control col-xs-10 col-sm-10" name="deadline" value="' + value.deadline + '" disabled></div></div>';
				},
				isTd:false
			},
			{
				name:'reviewTimes',
				input:"审核次数",
				type:"disabled",
 				isAdd:false
			},
			{
				name:function(index,value,isForInput){
 					if(isForInput)return 'productState';
 					if(value.productState == 1)return '<td><span class="label label-sm label-success">' + "已通过" + '</span></td>';
					else if(value.productState == 2)return '<td><span class="label label-sm label-error">' + "审核中" + '</span></td>';
					else if(value.productState == 3)return '<td><span class="label label-sm label-danger">' + "已拒绝" + '</span></td>';
 				},
 				type:"hidden",
 				isAdd:false
			},
			{
 				name:'reviewDate',
 				input:'审核时间',
 				type:"disabled",
 				isTd:false,
 				isAdd:false
 			},
 			{
 				name:'rejectReason',
 				input:function(value,isInit,isChar){
					if(isChar)return '拒绝原因';
					return '<div class="col-sm-9"><textarea class="form-control col-xs-10 col-sm-10" rows=5 name="rejectReason" placeholder="拒绝原因" disabled>' + value.rejectReason + '</textarea></div></div>';
				},
 				isTd:false,
 				isAdd:false
 			}
		];
		var parms = {
			pageNum:1,
			pageSize:10
		};
		var urls = {
			load:'product/info',
			detail:'product/detail',
			del:'product/del',
			edit:'product/upd',
			add:'product/add',
			delBatch:'product/delBatch',
		};
		var config = {
 			uploader:true,
 			datepicker:true,
 			listbtns:function(){
 				var html = '<div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">';
 				html += '<a class="single-edit blue" href="#modal-table" data-toggle="modal" title="查看详情"><i class="icon-zoom-in bigger-130"></i></a>';
 				html += '<a class="single-delete red" title="删除"><i class="icon-trash bigger-130"></i></a>';
 				html += '</div><div class="visible-xs visible-sm hidden-md hidden-lg"><div class="inline position-relative">';
 				html += '<ul class="dropdown-menu dropdown-only-icon dropdown-yellow pull-right dropdown-caret dropdown-close">';
 				html += '<li><a href="#modal-table" data-toggle="modal" class="single-edit tooltip-success" data-rel="tooltip" title="Edit"><span class="green"><i class="icon-edit bigger-120"></i></span></a></li>';
 				html += '<li><a class="single-delete tooltip-error" data-rel="tooltip" title="Delete"><span class="red"><i class="icon-trash bigger-120"></i></span></a></li>';
 				html += '</ul></div></div>';
 				return html;
 			},
 			formbtns:function(value){
 				var html = '';
 				if(value.productState == 2){
 					html += '<button type="button" class="single-edit-pass btn btn-sm btn-primary"><i class="icon-ok bigger-110"></i>通过审核</button>&nbsp; &nbsp; &nbsp;';
 					html += '<button type="button" class="single-edit-sub btn btn-sm btn-success"><i class="icon-tag bigger-110"></i>上传附件</button>&nbsp; &nbsp; &nbsp;';
 					html += '<button type="button" class="single-edit-reject btn btn-sm btn-danger"><i class="icon-remove bigger-110"></i>驳回请求</button>'; 					
 				}else{
 					html += '<button type="button" class="single-edit-sub btn btn-sm btn-success"><i class="icon-tag bigger-110"></i>上传附件</button>';
 				}
 				return html;
 			},
 			callback:{
 				forEdit:function(value,names,parms,urls,config,isLoadPls){
 					$(".single-edit-pass").click(function(){
 						bootbox.dialog({
							message: "<span class='bigger-110'>确认是否通过审核</span>",
							buttons: 			
							{
								"danger" :
								{
									"label" : "确认",
									"className" : "btn-sm btn-danger",
									"callback": function() {
										$.post("product/pass",{id:value.id},function(){
											$(".uploader-container").find('input[for-format=empty-uploader]').attr("removeView",true);
											$(".uploader-container").find('input[for-format=empty-uploader]').click();
											$("#modal-close-btn").click();
											$.loadTbl(names,parms,urls,config,isLoadPls);
										});
									}
								}, 
								"click" :
								{
									"label" : "取消",
									"className" : "btn-sm btn-primary",
									"callback": function() {
										//Example.show("Primary button");
									}
								}, 
							}
						});
 					});
					$(".single-edit-reject").click(function(){
						bootbox.prompt("请填写驳回原因", function(result) {
							if (result === null) {
							} else {
								if(result == ""){
									alert("未填写驳回原因");
									return;
								}
								$.post("product/reject",{
									id:value.id,
									reviewDate:value.reviewDate,
									rejectReason:result
								},function(){
									$(".uploader-container").find('input[for-format=empty-uploader]').attr("removeView",true);
									$(".uploader-container").find('input[for-format=empty-uploader]').click();
									$("#modal-close-btn").click();
									$.loadTbl(names,parms,urls,config,isLoadPls);
								});
							}
						});

 					});
 				}
 			}
 		};
		$.loadTbl(names,parms,urls,config,true);
	});
	jQuery(function($) {
		$('table th input:checkbox').on('click' , function(){
			var that = this;
			$(this).closest('table').find('tr > td:first-child input:checkbox')
			.each(function(){
				this.checked = that.checked;
				if(that.checked == true)$(this).closest('tr').addClass('selected');
				else $(this).closest('tr').removeClass('selected');
			});
				
		});
	
		$('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
		function tooltip_placement(context, source) {
			var $source = $(source);
			var $parent = $source.closest('table')
			var off1 = $parent.offset();
			var w1 = $parent.width();
	
			var off2 = $source.offset();
			var w2 = $source.width();
	
			if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
			return 'left';
		}
	})
	</script>
</body>